import ply.lex as lex

tokens = (
	'NUMBER',
	'PLUS',
	'MINUS',
	'TIMES',
	'DIV',
	'LPAREN',
	'RPAREN',
)

t_PLUS		= r'\+'
t_MINUS		= r'-'
t_TIMES		= r'\*'
t_DIV		= r'/'
t_LPAREN	= r'\('
t_RPAREN	= r'\)'

def t_NUMBER (t):
	r'\d+'
	t.value = int(t.value)
	return t

t_ignore = ' \t\n'

def t_error (t):
	print "illegal character '%s'" % t.value[0]
	t.lexer.skip(1)

lexer = lex.lex()

data = '''
1 + 2 - 3 * 4 / 5
'''

lexer.input(data)

while True:
	tok = lexer.token()
	if not tok: break
	print tok


